import 'package:dio/dio.dart';

// 根据userId获取Schedule
Future<Response<dynamic>> getScheduleByUserId({
  required int userId,
  required Dio dio,
}) async {
  Response<dynamic> response = await dio.get('/schedule/$userId');
  return response;
}

// 根据userId和日期获取Schedule
Future<Response<dynamic>> getScheduleByUserIdAndDate({
  required int userId,
  required String date,
  required Dio dio,
}) async {
  Response<dynamic> response = await dio.get('/schedule/$userId/date/$date');
  return response;
}

// 根据userId, 日期和dateId获取Schedule
Future<Response<dynamic>> getScheduleByUserIdAndDateAndDateId({
  required int userId,
  required String date,
  required int dateId,
  required Dio dio,
}) async {
  Response<dynamic> response =
      await dio.get('/schedule/$userId/date/$date/dateId/$dateId');
  return response;
}

// 根据userId添加Schedule
Future<Response<dynamic>> addScheduleByUserIdAndName({
  required int userId,
  required String outfitName,
  required Map<String, dynamic> scheduleData,
  required Dio dio,
}) async {
  try {
    Response<dynamic> response = await dio.post(
      '/schedule/$userId/outfitName/$outfitName',
      data: scheduleData,
    );
    return response;
  } catch (e) {
    throw Exception('添加日程失败: $e');
  }
}

Future<Response<dynamic>> addAiSuggestionToScheduleById({
  required int id,
  required String aiSuggestion,
  required Dio dio,
}) async {
  try {
    Response<dynamic> response = await dio.post(
      '/schedule/$id/aiSuggestion/',
      data: aiSuggestion, // 直接发送字符串
      options: Options(
        contentType: 'text/plain', // 设置 Content-Type 为纯文本
      ),
    );
    return response;
  } catch (e) {
    if (e is DioException) {
      print('DioException: ${e.response?.data}');
    } else {
      print('Exception: $e');
    }
    throw Exception('添加AI建议失败: $e');
  }
}

Future<Response<dynamic>> deleteScheduleByUserIdAndDate({
  required int userId,
  required String date,
  required Dio dio,
}) async {
  Response<dynamic> response = await dio.delete('/schedule/$userId/date/$date');
  return response;
}

// 根据userId, 日期和dateId更新Schedule
Future<Response<dynamic>> updateScheduleByUserIdAndDateAndDateId({
  required int userId,
  required String date,
  required String content,
  required String aiSuggestion,
  required int dateId,
  required Dio dio,
}) async {
  Response<dynamic> response = await dio.put(
    '/schedule/$userId/date/$date/dateId/$dateId',
    queryParameters: {
      'content': content,
      'aiSuggestion': aiSuggestion,
    },
  );
  return response;
}

// 根据userId, 日期和dateId删除Schedule
Future<Response<dynamic>> deleteScheduleByUserIdAndDateAndDateId({
  required int userId,
  required String date,
  required int dateId,
  required Dio dio,
}) async {
  Response<dynamic> response =
      await dio.delete('/schedule/$userId/date/$date/dateId/$dateId');
  return response;
}
